< previous page page_622 next page >

Page 622
e10a6a0a59f035e870d90cca05b85fce.gif
     Nz = pz - (Point1.Trans(3) + HitU * Vz)
     n_len = Sqr(Nx * Nx + Ny * Ny + Nz * Nz)
     Nx = Nx / n_len
     Ny = Ny / n_len
     Nz = Nz / n_len

     ' Get the hit color.
     CalculateHitColor depth, Objects, Me, _
         eye_x, eye_y, eye_z, _
         px, py, pz, _
         Nx, Ny, Nz, _
         DiffuseKr, DiffuseKg, DiffuseKb, _
         AmbientKr, AmbientKg, AmbientKb, _
         SpecularK, SpecularN, _
         ReflectedKr, ReflectedKg, ReflectedKb, IsReflective, _
         TransmittedKr, TransmittedKg, TransmittedKb, TransN, _
         n1, n2, IsTransparent, R, G, B
End Sub
Figure 17.19 shows program VBRay displaying six spheres and three cylinders.
Recursive Ray Tracing
Ray tracing as presented in the previous sections is quite useful. It does everything the hidden surface and shading algorithms described in earlier chapters do. It also performs smooth shading (as long as you can find equations for your objects), and it displays shadows. With only a little more work, you can make ray tracing model reflective and transparent surfaces, too.
The basic idea is to break the light transmitted at a point into local and global components. The local components are those that are caused locally at the point by ambient light and diffuse and specular reflection modified by shadowing. The global components
0622-01.jpg
Figure 17.19
Six spheres and three cylinders.

 
< previous page page_622 next page >